/**
 * 
 */
package com.example.validation.controler;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.validation.constraints.AssertTrue;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.Email;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Past;
import javax.validation.constraints.Size;

import com.alibaba.fastjson.JSONObject;
import com.example.validation.utils.EnumValue;
import com.fasterxml.jackson.annotation.JsonFormat;

import lombok.Data;

/**
 * @author xiazhengjiao
 * @date 2019年5月31日
 */
@Data
public class DemoDTO {

	@NotBlank(message = "用户Id不能为空")
	private String userId;

	@NotEmpty(message = "countId不能为空")
	private List<String> count;

	@Min(value = 0, message = ">0")
	private Integer age;

	@EnumValue(enumValue = OrderEnum.class, message = "必须输入1或2")
	private String sts;

	@AssertTrue(message = "flag必须是布尔值")
	private Boolean flag;

	// 使用自定义校验注解->校验时间
	@Past(message = "生日只能为以前的时间")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm")
	private Date birth;

	// 校验Email
	@Email(message = "邮件地址不正确")
	private String email;

	@DecimalMin(value = "0.0", message = "单价最低为0.00")
	private double price; // getter setter ....... }

	@Size(max = 3, message = "最大长度3")
	private String otherCostDescription;

	public static void main(String[] args) {
		DemoDTO dto = new DemoDTO();
		dto.setAge(1);
		dto.setFlag(true);
		dto.setSts("1");
		dto.setUserId("A01");
		List<String> c = new ArrayList<>();
		c.add("1");
		c.add("2");
		dto.setCount(c);
		System.out.print(JSONObject.toJSONString(dto));
	}
}
